from artSightWorld.apps.base.models import *
from artSightWorld.apps.base.views import *
from django.shortcuts import render_to_response
from django.template import RequestContext

def follow(request, idPhotographer):
	photographer = Photographer.objects.get(user__pk=request.user.pk)
	followed = Photographer.objects.get(user__pk=idPhotographer)
	photographer.photographersLiked.add(followed)
	photographer.save()
	return HttpResponseRedirect('/profile/'+idPhotographer)

def unfollow(request, idPhotographer):
	photographer = Photographer.objects.get(user__pk=request.user.pk)
	followed = Photographer.objects.get(user__pk=idPhotographer)
	photographer.photographersLiked.remove(followed)
	photographer.save()
	return HttpResponseRedirect('/profile/'+idPhotographer)
	
def addToFavorites(request, idPhoto):
	photographer = Photographer.objects.get(user__pk=request.user.pk)
	photo = Photo.objects.get(pk=idPhoto)
	photographer.photosLiked.add(photo)
	photographer.save()
	response = HttpResponse("ok", mimetype="plain/text")
	return response
	
def removeFromFavorites(request, idPhoto):
	photographer = Photographer.objects.get(user__pk=request.user.pk)
	photo = Photo.objects.get(pk=idPhoto)
	photographer.photosLiked.remove(photo)
	photographer.save()
	response = HttpResponse("ok", mimetype="plain/text")
	return response